from os import environ as env
import os

project_dir = os.path.dirname(os.path.abspath(__file__))
project_name = project_dir.split("/")[-1]
project_name_upper  = project_name.upper()
apps_dir = os.path.join(project_dir, "apps")

amqp_user = env.get('{}_AMQP_USER'.format(project_name_upper), 'guest')
amqp_passwd = env.get('{}_AMQP_PASSWD'.format(project_name_upper), 'guest')
amqp_host = env.get('{}_AMQP_HOST'.format(project_name_upper), 'localhost')
amqp_port = env.get('{}_AMQP_PORT'.format(project_name_upper), 5672)
amqp_space = env.get('{}_AMQP_SPACE'.format(project_name_upper), '/')


DEBUG = env.get("DEBUG")
app_env = env.get("APP_ENV", "")

db_host = env.get("{}_DB_HOST".format(project_name_upper), "127.0.0.1")
db_port = env.get("{}_DB_PORT".format(project_name_upper), 3306)
db_name = env.get("{}_DB_NAME".format(project_name_upper), None)
db_user = env.get("{}_DB_USER".format(project_name_upper), "root")
db_passwd = env.get("{}_DB_PASSWD".format(project_name_upper), "root")

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.mysql",
        "HOST": db_host,
        "PORT": db_port,
        "NAME": db_name,
        "USER": db_user,
        "PASSWORD": db_passwd
    }
}

BROKER_URL = 'amqp://{}:{}@{}:{}/{}'.format(
    amqp_user,
    amqp_passwd,
    amqp_host,
    amqp_port,
    amqp_space)
